﻿using System.Collections.Generic;
using GameProtocols;
using Network;
using LitJson;
using System.Collections;
using System;

public class PlayerManager : Singleton<PlayerManager>{
    
    Dictionary<long, Player> _playerMap = new Dictionary<long, Player>();
    public long MyPlayerID
    {
        get
        {
            return DetailPlayer.Instance.PlayerID;
        }
    }
    
    public PlayerManager()
    {

    }

    public void AddNewPlayer(Player player)
    {
        if (!_playerMap.ContainsKey(player.PlayerID))
        {
            _playerMap[player.PlayerID] = player;
        }
    }


    public Player GetPlayer(long playerId)
    {
        if (_playerMap.ContainsKey(playerId))
            return _playerMap[playerId];
        else
            return null;
    }

    public void DelPlayer(long playerId)
    {
        Player player = GetPlayer(playerId);
        if(player != null)
        {
            _playerMap.Remove(playerId);
        }
    }

    public Dictionary<long, Player> GetAllPlayers()
    {
        return _playerMap;
    }

    public void Reset()
    {
        _playerMap.Clear();
    }
}
